using System;
using NeuralNet;
using AGG;
using AGG.Image;
using AGG.UI;

namespace SmartSweeper
{
    public class SmartSweeperApplication : Reflexive.Game.GamePlatform
    {
        CController m_Controller;
        private static double rtri;                                              // Angle For The Triangle ( NEW )
        private static double rquad;                                             // Angle For The Quad ( NEW )
        AGG.UI.CheckBoxWidget m_SuperFast;

        public SmartSweeperApplication(GuiHalSurface drawingSurface)
            : base(60, 5, drawingSurface)
        {
        }

        bool firstTime = true;
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (firstTime)
            {
                firstTime = false;
                m_SuperFast = new AGG.UI.CheckBoxWidget(10, 10, "Run Super Fast");
                AddChild(m_SuperFast);
                m_Controller = new CController(NewGraphics2D().DestImage, 30, 40, .1, .7, .3, 4, 1, 2000);
            }

            graphics2D.Clear(new RGBA_Doubles(1, 1, 1, 1));
            graphics2D.Rasterizer.SetVectorClipBox(0, 0, (int)Width, (int)Height);
            m_Controller.FastRender(m_SuperFast.Checked);
            m_Controller.Render(graphics2D);
            //m_SuperFast.Render(graphics2D);
            base.OnDraw(graphics2D);
        }

        public override void OnUpdate(double NumSecondsPassed)
        {
            if (m_SuperFast.Checked)
            {
                for (int i = 0; i < 40; i++)
                {
                    m_Controller.Update();
                }
            }
            m_Controller.Update();
            rtri += 0.2f;                                                       // Increase The Rotation Variable For The Triangle ( NEW )
            rquad -= 0.15f;                                                     // Decrease The Rotation Variable For The Quad ( NEW )
            base.OnUpdate(NumSecondsPassed);
        }

        public static void StartDemo()
        {
            GuiHalFactory.SetGuiBackend(GuiHalFactory.KnownGuiFactoriesIndexes.WindowsFormsBitmap);
            GuiHalSurface primaryWindow = GuiHalFactory.CreatePrimarySurface(640, 480, GuiHalSurface.CreateFlags.Resizable, GuiHalSurface.PixelFormat.PixelFormatBgra32);

            primaryWindow.Caption = "Smart Sweepers";

            primaryWindow.AddChild(new SmartSweeperApplication(primaryWindow));
            primaryWindow.Run();
        }

        [STAThread]
        public static void Main(string[] args)
        {
        	StartDemo();
        }
    };
}
